/*
 * Copyright 2004-2005 asoft
 * 本软件及其所有拷贝的名称，与光盘上或本软件中注明的公司同在。
 * 本软件及文档享有版权，并受国家版权法及国际协约条款的保护。
 * 您不可以从本软件中去掉其版权声明；并保证为本软件的拷贝（本部或部分）* 复制版权声明。
 * 您同意制止以任何形式非法拷贝本软件及文档。
 * 版权信息参见：
 *      http://www.asoft.cn/licenses
 */

package com.asoft.examonline.exammanager.dao;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.apache.log4j.Logger;

import com.asoft.common.base.dao.BaseDAOHibernate;

/**
 * <p>Title: 试题</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: asoft</p>
 * @ $Author: author $
 * @ $Date: 2005/02/16 08:27:39 $
 * @ $Revision: 1.17 $
 * @ created in 2007-2-20
 *
 */

public class ExamQuestionDAOimp extends BaseDAOHibernate
                             implements ExamQuestionDAO
{
        static Logger logger = Logger.getLogger(ExamQuestionDAOimp.class);

        /**
         * 描述:查询试题s
         *
         * @ param:
         * @ param:orderBy 排序属性（for hql）
         * @ param:sortType 排序方式（asc or desc）
         * @ Exception:
         * @ return model集合
         */
        public List findExamQuestions(String domainId,
                                      String subjectId,
                                      String courseId,
                                      String unitId,
                                      String sectionId,
                                      String knowledgePointId,
                                      String knowledgeTypeId,
                                      String questTypeId,
                                      String difficultyId,
                                      String sourceId,
                                      String authorName,
                                      String content,
                                      String orderBy,
                                      String sortType)
        {
                String hql = 
                        " from ExamQuestion eq " +
                        " where " +
//                        "     eq.knowledgePoint.superType.superType.superType.superType.superType.id like ? " +
//                        " and eq.knowledgePoint.superType.superType.superType.superType.id like ? " +
//                        " and eq.knowledgePoint.superType.superType.superType.id like ? " +
//                        " and eq.knowledgePoint.superType.superType.id like ? " +
//                        " and eq.knowledgePoint.superType.id like ? " +
//                        " and eq.knowledgePoint.id like ? " +
//                        " and eq.questType.id like ? " +
//                        " and eq.difficulty.id like ? " +
//                        " and eq.source.id like ? " +
//                        " and " +
                        
                        "    eq in (" +
                        " select elements(kp.examQuestions ) " +
                        " from Type kp " +
                        " where " +
                        "     kp.superType.superType.superType.superType.superType.id like ? " +
                        " and kp.superType.superType.superType.superType.id like ? " +
                        " and kp.superType.superType.superType.id like ? " +
                        " and kp.superType.superType.id like ? " +
                        " and kp.superType.id like ? " +
                        " and kp.id like ? " +                        
                        " ) " +
                        " and eq.questType.id like ? " +
                        " and eq.difficulty.id like ? " +
                        " and eq.source.id like ? " +                        
                        " and eq.authorName like ? " +
                        " and eq.content like ? " +
                        " order by " + orderBy + " " + sortType;
                Object[] values = new Object[] {
                                                domainId,
                                                subjectId,
                                                courseId,
                                                unitId,
                                                sectionId,
                                                knowledgePointId,
                                                questTypeId,
                                                difficultyId,
                                                sourceId,
                                                "%" + authorName + "%",
                                                "%" + content + "%"};
                return this.iterator2List(this.getHibernateTemplate().iterate(hql,values));
        }  
        
        /**
         * 描述:查询试题s by 知识点
         *
         * @ param:
         * @ param:orderBy 排序属性（for hql）
         * @ param:sortType 排序方式（asc or desc）
         * @ Exception:
         * @ return model集合
         */
        public List findExamQuestionsByKnowledgePoint(String knowledgePointId)
        {
                String hql = 
                        " from ExamQuestion eq " +
                        " where " +
                        "    eq in (" +
                        " select elements(kp.examQuestions ) " +
                        " from Type kp " +
                        " where " +
                        "     kp.id = ? " +                        
                        " ) " ;
                Object[] values = new Object[] {knowledgePointId};
                return this.iterator2List(this.getHibernateTemplate().iterate(hql,values));
        }
        
}
